<template>
  <div class="hall_nav">
    <div class="create" @click="createChatRoom">
      <svg class='icon' aria-hidden='true'>
        <use xlink:href='#icon-chuangjianpindao'></use>
      </svg>
      <span>创建房间</span>
    </div>
    <div class="channels">
      <div class="channel">
        <svg class='icon' aria-hidden='true'>
          <use xlink:href='#icon-pindao'></use>
        </svg>
        <span>频道</span>
      </div>
      <ul>
        <li @click="filterRoom(item,index)" :class="{active:index==channel_index}" class="btn" v-for="(item,index) in channels" :key="index">
          <svg class='icon' aria-hidden='true'>
            <use :xlink:href='item.icon'></use>
          </svg>
          {{item.text}}
        </li>
      </ul>
    </div>
    <create-room :channels="channels" v-show="showCreate" @off="showCreate=false"></create-room>
  </div>
</template>

<script>
import { mapActions } from 'vuex';
import createRoom from "./room/createRoom.vue"
export default {
  name: 'Nav',

  data() {
    return {
      // channels: ['全部频道','生活情感','学习交流','娱乐游戏','聊天交友','其他'], // 菜单数据集
      channels: [
        {text: '全部频道', icon: '#icon-quanbu'},{text: '生活情感', icon: '#icon-qinggan'},{text: '学习交流',icon: '#icon-xuexi'},{text: '娱乐游戏',icon: '#icon-yule'},
        {text: '聊天交友', icon: '#icon-jiaoyou'},{text: '其他', icon: '#icon-kuozhan'}
      ],
      channel_index: 0, // 菜单索引
      showCreate: false, // 显示创建房间表单
    }
  },

  methods: {
    // 过滤房间
    filterRoom(item,index){
      console.log(item)
      this.channel_index = index
      this.$emit('filterRoom',item.text)
    },
    // 打开创建房间表单
    createChatRoom(){
      if(this.$store.state.isLogin){
        this.showCreate = true
      }else{
        this.showHint({title:'请先登陆',isFlag:false})
      }
    },
    ...mapActions(['showHint'])
  },

  components: {
    createRoom
  }
};
</script>

<style scoped>
.hall_nav{
  background-color: white;
  display: flex;
  flex-direction: column;

}
.create{
  display: inline-block;
  padding: 8px 10px;
  background-color: green;
  color: white;
  font-size: 0.8rem;
  cursor: pointer;
}
.create .icon{
  font-size: 15px;
}
.create:hover{
  color: red;
}
.create span{
  margin-left: 2px;
}
.channels{
  margin-top: 10px;
  padding: 10px;
}
.channels .channel .icon{
  font-size: 1.5em;
}
.channel span{
  font-weight: 600;
}
.channels ul{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.channels .btn{
  width: 80px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  font-size: 0.6rem;
  border: 1px solid gray;
  border-radius: 10px;
  margin-top: 10px;
  cursor: pointer;
  transition: all .3s ease;
}
.channels .btn:hover{
  background-color: gray;
  color: white;
}
.channels .icon{
  font-size: 15px;
}
.channels .active{
  background-color: gray;
  color: white;
}
@media screen and (max-width:800px) {
  .channels ul{
    justify-content: flex-start;
  }
  .channels ul li{
    margin-right: 10px;
  }
}
</style>